{extend name="base" /} {block name="css"}
{/block} {block name="body"}
<style>
    .layui-layedit-iframe iframe {
        height: 500px !important;
    }
</style>
<!--tab标签-->
<div class="layui-tab-brief">

    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <form class="layui-form form-container" data-url="{:url('admin/siteAdmin/save')}"
                  localtion-url="{:url('admin/siteAdmin/index')}">
                <div class="layui-row layui-col-space15 layui-form-item">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">所在分类</label>
                        <div class="layui-input-block">
                            <select lay-verify="required" name="category_id" lay-filter="category_id">
                                {volist name="$category_level_list" id="vo"}
                                <option  value="{$vo.id}">{neq name="vo.level" value="1"}|{php}for($i=1;$i<$vo['level'];$i++){echo '--';}{/php}{/neq}{$vo.name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">网址</label>
                        <div class="layui-input-block">
                            <input id="link" name="link" title="输入网址后请使用右侧的更新按钮" type="text"
                                   placeholder="点击标题可直接跳转（需以http或开头）" value=""
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">网站名称</label>
                        <div class="layui-input-block">
                            <input type="text" id="title" name="title"  required=""
                                   lay-verify="required" autocomplete="off" class="layui-input"/>
                        </div>
                    </div>

                    <div class="layui-col-md3">
                        <button id="updatePic" class="layui-btn layui-btn-sm layui-btn-warm"
                                style="float: right;marker-left:10px"><i class="layui-icon layui-icon-refresh"
                                                                         style="font-size: 30px;"></i>拉取图标LOGO
                        </button>
                        <button id="updateSeo" class="layui-btn layui-btn-sm layui-bg-blue" style="float: right;"><i
                                class="layui-icon layui-icon-refresh" style="font-size: 30px;"></i>更新爱站SEO信息
                        </button>
                    </div>
                </div>
                <div class="layui-row layui-col-space15 layui-form-item">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">备案号</label>
                        <div class="layui-input-block">
                            <input id="icp_id" name="icp_id" type="text" placeholder=""  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md4">
                        <label class="layui-form-label">简介</label>
                        <div class="layui-input-block">
                            <input type="text" id="site_short_content" name="site_short_content" required="" lay-verify="required" autocomplete="off" class="layui-input"/>
                        </div>
                    </div>
                    <div class="layui-col-md5">
                        <label class="layui-form-label">关键词</label>
                        <div class="layui-input-block">
                            <input type="text" id="keywords" name="keywords"  required=""
                                   lay-verify="required" autocomplete="off" class="layui-input"/>
                        </div>
                    </div>

                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">网站描述</label>
                    <div class="layui-input-block">
                        <input id="site_content" name="site_content" type="text"  autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-row layui-col-space15 layui-form-item">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">标题颜色</label>
                        <div class="layui-input-block">
                            <span id="colorSelect" style="display: block;float:left"></span>
                            <input id="color" name="color" type="text"  class="layui-input"
                                   style="display: block;float:left;width: 100px"/>
                            </span>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">排序</label>
                        <div class="layui-input-block">
                            <input type="number" name="sort" title="数字越大越靠前" value="0" class="layui-input"/>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">设置星级</label>
                        <div class="layui-input-block">
                            <div id="starSelect"></div>
                            <input type="hidden" id="stars" name="stars" class="layui-input"/>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">站长QQ</label>
                        <div class="layui-input-block">
                            <input type="text" name="webmaster_qq"  class="layui-input"/>
                        </div>
                    </div>
                </div>
                <div class="layui-row layui-col-space15 layui-form-item">
                    <div class="layui-form-item">
                        <label class="layui-form-label">站标</label>
                        <div class="layui-input-inline" style="width: auto;    margin-right:0px">
                            <button type="button" class="layui-btn uploadlogo" data-id="ico" id="up_ico_button">
                                <i class="layui-icon"></i>上传图片
                            </button>
                            <input class="layui-upload-file" type="file" accept="undefined" name="file">
                        </div>
                        <div class="layui-input-inline" style="width: calc(100% - 234px);">
                            <input type="text" id="ico" name="ico"  class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-row layui-col-space15 layui-form-item">
                    <div class="layui-form-item">
                        <label class="layui-form-label">Logo</label>
                        <div class="layui-input-inline" style="width: auto;    margin-right:0px">
                            <button type="button" class="layui-btn uploadlogo" data-id="logo_path"  id="up_logo_button">
                                <i class="layui-icon"></i>上传图片
                            </button>
                            <input class="layui-upload-file" type="file" accept="undefined" name="file">
                        </div>
                        <div class="layui-input-inline" style="width: calc(100% - 234px);">
                            <input type="text" id="logo_path" name="logo_path" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-row layui-col-space15 layui-form-item">
                    <div class="layui-form-item">
                        <label class="layui-form-label">首页缩略图</label>
                        <div class="layui-input-inline" style="width: auto;margin-right:0px">
                            <button type="button" class="layui-btn uploadlogo" data-id="screenshot_path" id="up_screenshot_button">
                                <i class="layui-icon"></i>上传图片
                            </button>
                            <input class="layui-upload-file" type="file" accept="undefined" name="file">
                        </div>
                        <div class="layui-input-inline" style="width: calc(100% - 234px);">
                            <input type="text" id="screenshot_path" name="screenshot_path" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-row layui-col-space15 layui-form-item">
                    <div class="layui-col-md4">
                        <label class="layui-form-label">Ico图</label>
                        <div class="layui-upload-list">

                            <img class="layui-upload-img" id="ico_show" style="max-height: 70px">
                        </div>
                    </div>
                    <div class="layui-col-md4">
                        <label class="layui-form-label">Logo图</label>
                        <div class="layui-upload-list">

                            <img class="layui-upload-img" id="logo_path_show" style="max-height: 100px"
                                 src="">
                        </div>
                    </div>
                    <div class="layui-col-md4">
                        <label class="layui-form-label">缩略图</label>
                        <div class="layui-inline" style="margin-left:0px;width:calc(100% - 128px);">

                            <img class="layui-upload-img" id="screenshot_path_show" style="max-height: 200px"
                                 src="">
                        </div>
                    </div>
                </div>

                <div class="btable-paged">

                    <div class="formbtngroup">

                        <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="formadd">提交</button>
                        <button onclick="history.go(-1);return false;" class="layui-btn layui-btn-primary layui-btn-sm">返回
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
{/block} {block name="js"}
<script type="text/javascript" src="__ADMIN__/js/formadd.js"></script>
<script>
    layui.use(['upload', 'colorpicker', 'rate'], function () {
        var jq = layui.jquery;
        var colorpicker = layui.colorpicker;
        var rate = layui.rate;
        var upload = layui.upload;
        upload.render({
            elem: '.uploadlogo',
            url: '{:url("upload/upimage")}',
            exts: 'jpg|png|gif|bmp|jpeg|ico',
            done: function (res, index, upload) {
                if (res.code == '0') {
                    var item = this.item;
                    var btnid = item.data('id');
                    var rurl = "__ROOT__";
                    $('#' + btnid).val(res.data.src);
                    $('#' + btnid + '_show').attr('src', rurl + res.data.src);
                    return layer.msg('上传成功');
                } else {

                    return layer.msg(res.msg);
                }
            }
        });
        //渲染
        var ins1 = rate.render({
            elem: '#starSelect'  //绑定元素
            , choose: function (value) {
                jq('#stars').val(value);
            }
        });
        //渲染
        colorpicker.render({
            elem: '#colorSelect'  //绑定元素
            , done: function (color) {
                jq('#color').val(color);
                console.log(color)
                //譬如你可以在回调中把得到的 color 赋值给表单
            }
        });
        jq('#updatePic').on('click', function () {
            $.ajax({
                url: "{:url('SiteAdmin/getIcoPicScreen')}",
                dataType: "json",
                data: {
                    url: jq('#link').val()
                },
                success: function (res) {
                    if (res.code == 1) {
                        var data = res.data;
                        jq('#ico').val(data.ico);
                        jq('#screenshot_path').val(data.screenshot);
                        jq('#ico_show').attr('src', data.ico);
                        jq('#screenshot_path_show').attr('src', data.screenshot);
                    } else {
                        layer.msg('获取超时，请手动上传');
                    }
                }
            });
            return false;
        });
        jq('#updateSeo').on('click', function () {
            $.ajax({
                url: "{:url('SiteAdmin/getSeoData')}",
                dataType: "json",
                data: {
                    url: jq('#link').val()
                },
                success: function (res) {
                    if (res.code == 1) {
                        var data = res.data;
                        jq('#title').val(data.title);
                        jq('#site_short_content').val(data.short_desc);
                        jq('#site_content').val(data.description);
                        jq('#keywords').val(data.keywords);
                        jq('#icp_id').val(data.icp_id);
                    } else {
                        layer.msg('获取超时，请稍后再试，你也可以手动填写');
                    }
                }
            });
            return false;
        });
    });
</script>
{/block}